Skip to main content

Color Marker System Examples

This document provides practical examples and visualizations of how the Color Marker System works in SELF Chain.

Basic Transaction Exampleโ€‹

Initial Stateโ€‹

Wallet Address: 0x742d35Cc6634C0532925a3b844Bc9e7595f2bD47
Initial Color: #3A7BD5 (Blue shade)
Balance: 1000 SELF

Transaction Detailsโ€‹

Sender: 0x742d35Cc6634C0532925a3b844Bc9e7595f2bD47
Receiver: 0x8B3f5Af2958438D676E4F7144C5F2B5E7A6c2Fb8
Amount: 100 SELF
Timestamp: 1704123456
Nonce: 42

Color Calculation Processโ€‹

  1. Generate Transaction Hash
Transaction Data = sender || receiver || amount || timestamp || nonce
Transaction Hash = SHA256(Transaction Data)
= 0xA3F2B7C9E4D1A8F6B2C7E9D4A1F8B6C2E7D9A4F1B8C6E2D79AF4B1C8E6D2A97F
  1. Divide into 6 Parts
Part 1: A3F2B7C9E4
Part 2: D1A8F6B2C7
Part 3: E9D4A1F8B6
Part 4: C2E7D9A4F1
Part 5: B8C6E2D79A
Part 6: F4B1C8E6D2
  1. Reduce Each Part
Part 1: A+3+F+2+B+7+C+9+E+4 = 59 โ†’ 5+9 = 14 โ†’ 1+4 = 5
Part 2: D+1+A+8+F+6+B+2+C+7 = 54 โ†’ 5+4 = 9
Part 3: E+9+D+4+A+1+F+8+B+6 = 56 โ†’ 5+6 = 11 โ†’ 1+1 = 2
Part 4: C+2+E+7+D+9+A+4+F+1 = 53 โ†’ 5+3 = 8
Part 5: B+8+C+6+E+2+D+7+9+A = 52 โ†’ 5+2 = 7
Part 6: F+4+B+1+C+8+E+6+D+2 = 51 โ†’ 5+1 = 6
  1. Form Transaction Color
Transaction Color = #592876
  1. Calculate New Wallet Color
Current Color: #3A7BD5 (decimal: 3832789)
Transaction Color: #592876 (decimal: 5843062)
New Color: (3832789 + 5843062) mod 16777216 = #9460FB (Purple shade)

Multi-Transaction Sequenceโ€‹

Transaction Chain Exampleโ€‹

Initial State: Wallet #FF5733 (Orange)

Transaction 1: Send 50 SELF
- Transaction Color: #1A2B3C
- New Wallet Color: #19839F (Blue-green)

Transaction 2: Receive 75 SELF
- Transaction Color: #4D5E6F
- New Wallet Color: #66E20E (Light green)

Transaction 3: Send 25 SELF
- Transaction Color: #7890AB
- New Wallet Color: #DF72B9 (Pink)

Validation Exampleโ€‹

Block Builder Processโ€‹

{
"block": {
"height": 123456,
"transactions": [
{
"tx_hash": "0xA3F2B7...",
"sender": "0x742d35...",
"receiver": "0x8B3f5A...",
"amount": 100,
"sender_color_before": "#3A7BD5",
"sender_color_after": "#9460FB",
"transaction_color": "#592876"
}
]
}
}

AI Validator Verificationโ€‹

# Pseudocode for validation
def validate_color_transitions(block):
for tx in block.transactions:
# Recalculate transaction color
calculated_tx_color = calculate_transaction_color(tx.tx_hash)

# Verify transaction color matches
if calculated_tx_color != tx.transaction_color:
return False

# Verify color transition
expected_new_color = (tx.sender_color_before + calculated_tx_color) % 0xFFFFFF
if expected_new_color != tx.sender_color_after:
return False

return True

Edge Casesโ€‹

Color Overflow Exampleโ€‹

Current Color: #FEDCBA (16702650)
Transaction Color: #123456 (1193046)
Sum: 17895696
New Color: 17895696 mod 16777216 = #1118480 โ†’ #111111 (Dark gray)

Zero Transaction Exampleโ€‹

Transaction Amount: 0 SELF
Transaction Hash: Still unique due to timestamp and nonce
Color Transition: Still occurs, preventing spam

Visual Representationโ€‹

Color Progression Over Timeโ€‹

Block 1: #FF0000 (Red)    โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
Block 2: #FF7F00 (Orange) โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
Block 3: #FFFF00 (Yellow) โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
Block 4: #7FFF00 (Green) โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
Block 5: #00FF00 (Green) โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
Block 6: #00FF7F (Cyan) โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
Block 7: #00FFFF (Cyan) โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
Block 8: #007FFF (Blue) โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

Attack Detection Patternโ€‹

Normal Pattern:
Wallet A: #FF0000 โ†’ #FF5500 โ†’ #FFAA00 โ†’ #FFFF00 (Gradual progression)

Attack Pattern:
Wallet B: #FF0000 โ†’ #0000FF โ†’ #FF0000 โ†’ #0000FF (Suspicious oscillation)
โ†‘ Potential double-spend attempt detected

Performance Metricsโ€‹

Computation Timeโ€‹

Single Color Calculation: ~0.001ms
Block with 1000 transactions: ~1ms
Parallel validation (8 cores): ~0.125ms

Storage Requirementsโ€‹

Per Wallet Color State: 3 bytes
Per Transaction Color: 3 bytes
Block Color Merkle Root: 32 bytes
Total for 1M wallets: ~3MB

Integration Examplesโ€‹

Smart Contract Integrationโ€‹

// Solidity example
contract ColorAwareContract {
mapping(address => uint24) public walletColors;

function updateColor(address wallet, uint24 newColor) external {
require(msg.sender == validator, "Only validator can update");
require(isValidColorTransition(walletColors[wallet], newColor));
walletColors[wallet] = newColor;
}
}

API Response Exampleโ€‹

{
"wallet": "0x742d35Cc6634C0532925a3b844Bc9e7595f2bD47",
"current_color": "#9460FB",
"color_history": [
{"block": 123456, "color": "#3A7BD5"},
{"block": 123457, "color": "#9460FB"}
],
"pending_transactions": [
{
"tx_hash": "0xB4E9F2...",
"expected_color": "#A123BC"
}
]
}

Troubleshootingโ€‹

Common Issuesโ€‹

  1. Color Mismatch Error

    • Cause: Transaction ordering issue
    • Solution: Verify transaction sequence in mempool
  2. Validator Disagreement

    • Cause: Network partition during color update
    • Solution: Resync with majority color state
  3. Performance Degradation

    • Cause: Large block size
    • Solution: Implement parallel color validation

Debug Output Exampleโ€‹

[DEBUG] Wallet 0x742d35... color transition:
Current: #3A7BD5 (3832789)
Transaction: #592876 (5843062)
Expected: #9460FB (9675851)
Calculated: #9460FB (9675851)
Status: VALID โœ“

Best Practicesโ€‹

  1. Always Verify Color History: Check last N color transitions for consistency
  2. Cache Color States: Maintain recent color states in memory for fast validation
  3. Batch Validations: Process multiple color transitions in parallel
  4. Monitor Patterns: Use AI to detect unusual color progression patterns
  5. Regular Checkpoints: Store color state snapshots for fast synchronization

This comprehensive example set demonstrates the practical application of the Color Marker System in various scenarios, helping developers and validators understand its implementation and behavior.